package com.ymatou.iapi.userservice.testcase;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.BatchUserDetailsRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.enums.UserTypeEnum;
import com.ymatou.iapi.userservice.parameter.req.BriefBatchUserRequestDtoReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.resp.QueryBatchUserBriefNetResp;
import com.ymatou.iapi.userservice.service.BatchUserDetailsRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.constant.ECode;
/**
*根据userid批量查询用户明细信息Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BatchUserDetailsRequestDto{
	private static BatchUserDetailsRequestDtoBean batchuserdetailsrequestdtoBean;
	private static BatchUserDetailsRequestDtoCall batchuserdetailsrequestdtoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据userid批量查询用户明细信息Test");
	}

	@Before
	public void caseUp() {
		batchuserdetailsrequestdtoBean=new BatchUserDetailsRequestDtoBean();
		batchuserdetailsrequestdtoCall=new BatchUserDetailsRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(batchuserdetailsrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	private void verifyDB(BatchUserDetailsRequestDtoCall b1) throws JSONException {
		JUserWapper ju = new JUserWapper();
		ArrayList<QueryBatchUserBriefNetResp> list = b1.getResult();

		for (QueryBatchUserBriefNetResp Result : list) {
			List<Userinfo> lui = ju.selectUserinfoByUid(Result.getUserId());
			Userinfo ui = lui.get(0);
			List<Userinfoex> lui2 = ju.selectUserinfoexByUid(Result.getUserId());
			Userinfoex uiex = lui2.get(0);

			Logger.comment("验证Userinfo");

			Logger.verifyEquals(Result.getUserId(), ui.getUserId(), "验证iUserId");
			Logger.verifyEquals(Result.getLoginId(), ui.getLoginId(), "验证sLoginId");
			Logger.verifyEquals(Result.getLoginMail(), ui.getLoginMail(), "验证sLoginEmail");
			Logger.verifyEquals(Result.getLoginMobile(), ui.getLoginMobile(), "验证sLoginMobile");
			Logger.verifyEquals(Result.getUserType().getCode(), ui.getUserType(), "验证iType");
			Logger.verifyEquals(Result.getUserState(), ui.getUserState(), "验证userState");

			Logger.comment("验证Userinfoex");
			if(ui.getUserType()==0){
				Logger.verifyEquals(Result.getLogoUrl(), uiex.getLogoUrl()==null?"http://staticontent.ymatou.com/app/userlogo/mj.jpg": uiex.getLogoUrl(), "验证logUrl");
			}else if(ui.getUserType()==1){
				Logger.verifyEquals(Result.getLogoUrl(), uiex.getLogoUrl()==null?"http://staticontent.ymatou.com/app/userlogo/ms.jpg": uiex.getLogoUrl(), "验证logUrl");
			}
			Logger.verifyEquals(Result.getQq(), uiex.getQQ(), "验证qq");

		}

	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	//与json/reply/BatchUserRequestDto共用一个接口
	public void Tc_BatchUserDetailsRequestDto_001() {
		Logger.start(true, "根据userid查询单个用户明细信息,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String loginId = cur.getLoginId();
			List<Integer> userIdList = new ArrayList<>();
			userIdList.add(uid);
			batchuserdetailsrequestdtoBean.setUserIdList(userIdList);
			batchuserdetailsrequestdtoCall.setData(batchuserdetailsrequestdtoBean);
			batchuserdetailsrequestdtoCall.callService();
			
			Logger.verifyEquals(ECode.SUCCESS, batchuserdetailsrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", batchuserdetailsrequestdtoCall.getString("Success"), "验证Success");
			
			verifyDB(batchuserdetailsrequestdtoCall);
	

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_BatchUserDetailsRequestDto_002() {
		Logger.start(true, "批量查询多个用户");
		try {
			List<Integer> userIdList = new ArrayList<>();
			List<String> loginIdList = new ArrayList<>();
			for (int i = 0; i < 3; i++) {
				CreateUserReq cur = new CreateUserReq();
				cur = JUserCallService.initCreateUserBean(cur);
				Integer uid = JUserCallService.createUserCall(cur);
				String loginId = cur.getLoginId();
				loginIdList.add(loginId);
				userIdList.add(uid);
			}
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setUserType(UserTypeEnum.Seller);
			Integer uid = JUserCallService.createUserCall(cur);
			String loginId = cur.getLoginId();
			loginIdList.add(loginId);
			userIdList.add(uid);
			
			batchuserdetailsrequestdtoBean.setUserIdList(userIdList);
			batchuserdetailsrequestdtoCall.setData(batchuserdetailsrequestdtoBean);
			batchuserdetailsrequestdtoCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, batchuserdetailsrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", batchuserdetailsrequestdtoCall.getString("Success"), "验证Success");

			verifyDB(batchuserdetailsrequestdtoCall);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUserDetailsRequestDto_003() {
		Logger.start(true, "不输入参数UserIdList，失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String loginId = cur.getLoginId();
			List<Integer> userIdList = new ArrayList<>();
			userIdList.add(null);
			batchuserdetailsrequestdtoBean.setUserIdList(userIdList);
			batchuserdetailsrequestdtoCall.setData(batchuserdetailsrequestdtoBean);
			batchuserdetailsrequestdtoCall.callService();
			
			Logger.verifyEquals("200", batchuserdetailsrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", batchuserdetailsrequestdtoCall.getString("Success"), "验证Success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	

}